Release 10.1A: OpenEdge Development:
ProDataSets
Using the COPY-DATASET method for successive FILLs
This second
COPY-DATASETexample provides a variation on the earlierPickOrderprocedure. As it stands,PickOrder.wand its support procedureOrderSupport.pretrieve a set ofOrderheaders, and then in follow-on calls, theOrderLinesfor thoseOrders. All the items are retrieved along with the first set ofOrderLines. When you select a different set ofOrders, the target ProDataSet is emptied and you start over again.To show a possible use for
COPY-DATASET, let’s start by making some changes to the way PickOrderworks, which will cause a problem that will then need correcting.
![]()
To update your code:
- Create a copy of
PickOrder.wcalledPickOrderCopy.w.- Create a variation on
dsOrder.icalleddsOrderNoRepos.i, which does not have theREPOSITIONkeyword on theItemrelation, as shown:
This will be used in the
OrderSupportprocedure when it fills the ProDataSet, so that rather than retrieving allItemsregardless of their relationship to theOrderLines(which is whatREPOSITIONdoes on aFILL), it will retrieve only thoseItemsthat match one of theOrderLinesbeing filled at the same time.- Create a copy of
OrderSupport.pcalledOrderSupportCopy.p. IncludedsOrderNoRepos.iin place ofdsOrder.i, as shown:
- Edit the internal procedure
fetchOrderDetailinOrderSupportCopy.pto eliminate the second parameter, which is the flag indicating whetherItemshave been retrieved already or not. In this variation, you’ll always retrieveItemsfor the currentOrderLines(and only thoseItems). TheFILL-MODEfor thettItemtable needs to be changed toMERGE.APPENDmode is correct for thettOlinetable, because there won’t be any duplicateOrderLinesfor a given set ofOrders (althoughMERGEmode would work just as well).MERGEmode is needed for thettItemtable in case the sameItemis used in more than oneOrderLine.MERGEmode eliminates the duplicates, as shown:
- Back in
PickOrderCopy.w, change the Main Block to runOrderSupportCopy.pinstead ofOrderSupport.p- Change the
SalesRepLEAVEtrigger inPickOrderCopy.wto run the new version offetchOrders, with only two parameters, as shown:
- Change the
MOUSE-SELECT-DBLCLICKtrigger for thettOrderbrowse, likewise eliminating the second argument tofetchOrderDetail, as shown:
- Now try running the window procedure. Enter 1 for the
Customerand tab through the other fill-in fields. You’ll seeOrders forCustomer 1as before.- Double-click on the second
Order(number36). You see that only itsItemshave been retrieved to be displayed in theItembrowse:
![]()
- Now double-click on the next
Order, number79. ItsOrderLinesandItemsare retrieved and added to those already in the window procedure’s ProDataSet. So far so good.- Now double-click on the next
Order, number177. This time you get the following error:
![]()
What went wrong? Because the
APPENDmode on the ProDataSet parameter in theOrderbrowse trigger doesn’t eliminate duplicates, Progress attempted to add anItemto the window procedure’sttItemtable that was already used in anotherOrderLine, and was therefore already there. This violates the unique index on thettItemtable, and Progress complains accordingly.Since you can’t get the
APPENDparameter mode to do a merge for you, eliminating duplicates, how can you accomplish this?One way is to use the
COPY-DATASETmethod to combine the data from two ProDataSets, one which is already on the client, and the other which is retrieved into a separate ProDataSet from the support procedure.- To do this, insert the contents of the include files
dsOrderTT.ianddsOrder.iintoPickOrderCopy.w’s definitions section, and edit them to give unique names to the second copy of the ProDataSet and its temp-tables. The temp-tables should be namedttOrder2,ttOline2,ttOlineBefore2, andttItem2. The field and index names can stay the same. The new ProDataSet definition should look like this:
Remember that there is no way to have multiple instances of the same static ProDataSet or temp-table in a single Progress procedure, so the second ProDataSet and its temp-tables need distinct names. You could of course also use a dynamic ProDataSet as the second ProDataSet, as we showed in the previous example.
- Now re-edit the
MOUSE-SELECT-DBLCLICKtrigger on theOrderbrowse to remove the code that empties the target ProDataSet, and to receive the additionalOrders,OrderLines, andItemsinto a second ProDataSet that is then copied into the first one. For example:
The second argument to
COPY-DATASET, themerge-flagTRUE, tells Progress to merge data from ProDataSetdsOrder2intodsOrderrather than emptyingdsOrderfirst. Now when you rerun the window, retrieveOrders forCustomer 1, and selectOrders36,79, and177in turn, the error is gone, because new data is being merged into the original ProDataSet and duplicates automatically eliminated, as shown:
![]()
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |